package com.css.apps.base.org.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.util.StringHelper;

import com.css.apps.base.org.model.SSysOrgTree;
import com.css.apps.base.sys.model.SSys;
import com.css.core.configuration.Environment;
import com.css.db.query.QueryCache;
import com.css.util.Ajax;
import com.css.util.LogUtil;
import com.css.util.Messages;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

@SuppressWarnings("serial")
public class DirCustomTree extends AdminAction {

	private static Log log = LogFactory.getLog(GetOrgTree.class);
	private String uuid;
	private String parentId;
	private List<String> sysList;
	private SSysOrgTree item;
	private String exp_sysid;
	private String exp_series;
	private String des;

	@SuppressWarnings("unchecked")
	@Override
	protected String adminGo() {
		try {
			if (StringHelper.isNotEmpty(uuid)) {// 修改自定义组织机构树
				item = QueryCache.get(SSysOrgTree.class, uuid);
				des = item.getDes();
				String resStr = item.getExp();
				String str[] = resStr.split("，");
				String prefix[] = new String[str.length];
				String res[] = new String[str.length];
				for (int i = 0; i < str.length; i++) {
					prefix[i] = str[i].split("：")[0];
					if ("sysId".equals(prefix[i])) {
						res[i] = str[i].split("：")[1];
						exp_sysid = (res[i]);
					} else if ("series".equals(prefix[i])) {
						res[i] = str[i].split("：")[1];
						exp_series = (res[i]);
					} else if ("parentOrgId".equals(prefix[i])) {
						res[i] = str[i].split("：")[1];
						parentId = (res[i]);
					}
				}
				LogUtil.get(SSysOrgTree.class, uuid);
			} else {// 添加自定义组织机构树
			}
			sysList = QueryCache.idToObj(SSys.class, new QueryCache("select uuid from SSys order by sysId").listCache());
			return Action.SUCCESS;
		} catch (Exception ex) {
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.exception"));
			log.error(ex.getMessage(), ex);
			return Action.ERROR;
		}
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public List<String> getSysList() {
		return sysList;
	}

	public void setSysList(List<String> sysList) {
		this.sysList = sysList;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public SSysOrgTree getItem() {
		return item;
	}

	public void setItem(SSysOrgTree item) {
		this.item = item;
	}

	public String getExp_sysid() {
		return exp_sysid;
	}

	public void setExp_sysid(String exp_sysid) {
		this.exp_sysid = exp_sysid;
	}

	public String getExp_series() {
		return exp_series;
	}

	public void setExp_series(String exp_series) {
		this.exp_series = exp_series;
	}

	public String getDes() {
		return des;
	}

	public void setDes(String des) {
		this.des = des;
	}

}
